var applicationUrl = "http://localhost:8080/public-web";

$(function() {
	if (window.PIE) {
		$('input').each(function() {
			PIE.attach(this);
		});
		$('div.arrondi').each(function() {
			PIE.attach(this);
		});
	}
});

function toggleImage(labelId) {
	if ($(labelId + " img").length > 0) {
		var src = $(labelId + " img").attr("src");
		if (resultat = src.match("_on.png$")) {
			src = src.replace("_on", "_off");
		} else {
			src = src.replace("_off", "_on");
		}
		$(labelId + " img").attr("src", src);
	}
}

function removeImage(labelId) {
	if ($(labelId + " img").length > 0) {
		var src = $(labelId + " img").attr("src");
		src = src.replace("_on", "_off");
		$(labelId + " img").attr("src", src);
	}
}

function toggleDropdown(event, divId, labelId) {
	$(divId).toggle('fast');
	$(labelId).toggleClass('active');
	$('div' + labelId + ' a').toggleClass('active');
	toggleImage(labelId);
	event.stopPropagation();
}

function removeDropdown(divId, labelId) {
	$(divId).hide('fast');
	$(labelId).removeClass('active');
	$('div' + labelId + ' a').removeClass('active');
	removeImage(labelId);
}

/* dropdown menu settings and register */
$(function() {
	$('html').click(function() {
		removeDropdown('#settings_list', '#username');
		removeDropdown('#register_list', '#register');
	});
	$('#username').click(function(event) {
		toggleDropdown(event, '#settings_list', '#username');
	});
	$('#register').click(function(event) {
		toggleDropdown(event, '#register_list', '#register');
	});
});